package com.stanley.demo.app.vm

import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.LiveData
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.google.gson.Gson
import com.stanley.demo.app.model.User
import com.stanley.demo.app.model.UserRepository
import com.stanley.demo.app.model.WebService
import retrofit2.GsonConverterFactory
import retrofit2.Retrofit


class UserProfileViewModel : ViewModel() {
    /**
    @ViewModelInject constructor(
    @Assisted savedStateHandle:SavedStateHandle,
    userRepository: UserRepository)
     */
    //private val userId: String = savedStateHandle["userId"]?:throw java.lang.IllegalArgumentException("")
    val user: LiveData<User>
    get() {

        var retrofit: Retrofit = Retrofit.Builder()
            .baseUrl("https://api.github.com")
            .addConverterFactory(GsonConverterFactory.create(Gson()))
            .build()
        var webservice: WebService = retrofit?.create(WebService::class.java)
        var userRepository:UserRepository = UserRepository(webservice)
        return userRepository.getUser("12345")
    }
}